//
//  File.swift
//  LiteAccount
//
//  Created by 刘伟 on 2017/5/4.
//  Copyright © 2017年 刘伟. All rights reserved.
//

import UIKit

protocol BaseViewProtocal {
    var bgColor: UIColor { get }
    func setBaseViewConfig()
}

extension BaseViewProtocal where Self: UIViewController {
    var bgColor: UIColor {
        return UIColor.white
    }
    
    func setBaseViewConfig() {
        self.view.backgroundColor = UIColor.white
        if self.navigationController != nil {
            let backBarItem = UIBarButtonItem.init(title: "", style: .plain, target: nil, action: nil)
            self.navigationItem.backBarButtonItem = backBarItem
        }
    }
    
    func setGlassBG() {
        let bgImageView = UIImageView(image: UIImage(named:"bg_bridge.jpg"))
        bgImageView.frame.size = CGSize(width: view.frame.width, height: view.frame.height)
        bgImageView.contentMode = .scaleAspectFit
        self.view.addSubview(bgImageView)
        //首先创建一个模糊效果
        let blurEffect = UIBlurEffect(style: .light)
        //接着创建一个承载模糊效果的视图
        let blurView = UIVisualEffectView(effect: blurEffect)
        //设置模糊视图的大小（全屏）
        blurView.frame.size = CGSize(width: view.frame.width, height: view.frame.height)
        //添加模糊视图到页面view上（模糊视图下方都会有模糊效果）
        self.view.addSubview(blurView)
    }
    
    func initMJHearder(target: UIScrollView, selector: Selector) {
        let mjHeader = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: selector)
        mjHeader?.lastUpdatedTimeLabel.font = UIFont.systemFont(ofSize: 12)
        mjHeader?.lastUpdatedTimeLabel.textColor = .black
        mjHeader?.stateLabel.font = UIFont.systemFont(ofSize: 15)
        mjHeader?.stateLabel.textColor = .black
        target.mj_header = mjHeader
        
    }
    
    func initMJFooter(target: UIScrollView, selector: Selector) {
        let mjFooter = MJRefreshBackNormalFooter(refreshingTarget: self, refreshingAction: selector)
        mjFooter?.stateLabel.textColor = .black
        mjFooter?.stateLabel.font = UIFont.systemFont(ofSize: 15)
        target.mj_footer = mjFooter

    }
    
}
